<?php
/**
 * Created by PhpStorm.
 * User: xuho
 * Date: 2020-04-30
 * Time: 22:53
 */

namespace app\common\model\redis;


use app\common\service\ConfigService;
use app\common\service\RedisKeyService;
use think\facade\Cache;

class AccessTokenRedis extends BaseRedis
{
    public static function get($systemId): string
    {
        $config = ConfigService::authWechatMini($systemId);
        $redisKey = RedisKeyService::accessToken($config['appid']);
        if (empty(Cache::exists($redisKey))) {
            $res = \app\common\facade\mini\Cert::accessToken($config['appid'], $config['appsecret']);
            $res = json_decode($res, true);
            $accessToken = $res['access_token'];
            Cache::set($redisKey, $accessToken, 7000);
        } else {
            $accessToken = Cache::get($redisKey);
        }
        return $accessToken;
    }

}